Skip to content

Conversation

benaryorg
Copy link

@benaryorg benaryorg commented Sep 29, 2025

Details

Effectively this fixes s3 signatures for custom domains.
The solution for this is somewhat hacky, however it does apply cleanly on version/2025.2.4 and I have tested it and can confirm that it works.
I'll set this to draft state because I do not currently have the capacity to finish the testing and linting, so if anyone wants to pick this up, please go ahead.
To be perfectly honest, I just copied the stuff I use to generate such links personally straight out of my shell history into the source code.
It is however the only solution that I have managed to find which actually works.
NB: this has only been tested when cherry-picked onto 2025.2.3 and 2025.8.3!
NB: this is more or less a bandaid, a proper rewrite of the method to generate the URl would be desirable IMHO, especially since it will compute the signature even when it is not needed. Using the proper class for the URl would also be good, to avoid any weirdnesses for edge-cases. Right now the onus of providing a working string is put on the admin.

The commit message is included verbatim below.


S3 signatures are fickle since there are several hashes of components which must ultimately be correct for the signature to match with no room for error.
Since both the host header as well as the path, the former by default, the latter necessarily.
The issue with custom domains is therefore that the host header mismatches unless the signature was created for that specific domain.
This is complicated further by boto3 making it incredibly difficult to actually sign a link with the path not containing the bucket prefix.
Therefore setting the endpoint alone does not work with a truly custom domain (i.e. one where the data resides on the root of the domain).

Changing this to a rather hacky workaround accessing fields of the internal data structures and grabbing the signer directly allows for signing the request.
This comes with several caveats such as the parameters going largely untouched, however in preliminary testing it works fine.
There are no superfluous slashes (i.e. no https://example.com//file.svg), no superfluous prefixes (i.e. https://example.com/example.com/example.com/file.svg), and there are no signature errors in general.
Uploads still work.
Reminder that the application cache may need clearing before the changes reflect in the non-admin UI.

Relates:


Checklist

  • Local tests pass (ak test authentik/)
  • The code has been formatted (make lint-fix)

If an API change has been made

  • The API schema has been updated (make gen-build)

If changes to the frontend have been made

  • The code has been formatted (make web)

If applicable

  • The documentation has been updated
  • The documentation has been formatted (make docs)

Copy link

netlify bot commented Sep 29, 2025

Deploy Preview for authentik-storybook ready!

Name Link
🔨 Latest commit 217964c
🔍 Latest deploy log https://app.netlify.com/projects/authentik-storybook/deploys/68e8f0fba542bd00085ded08
😎 Deploy Preview https://deploy-preview-17087--authentik-storybook.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

Copy link

netlify bot commented Sep 29, 2025

Deploy Preview for authentik-docs ready!

Name Link
🔨 Latest commit 217964c
🔍 Latest deploy log https://app.netlify.com/projects/authentik-docs/deploys/68e8f0fb16ad3000084f5e01
😎 Deploy Preview https://deploy-preview-17087--authentik-docs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

Copy link

netlify bot commented Sep 29, 2025

Deploy Preview for authentik-integrations canceled.

Name Link
🔨 Latest commit 217964c
🔍 Latest deploy log https://app.netlify.com/projects/authentik-integrations/deploys/68e8f0fb3965280009fe8de8

@benaryorg
Copy link
Author

benaryorg commented Sep 29, 2025

sh: 1: cross-env: not found

and

npm error No workspaces found

I'm not 100% sure, but the CI failures sound unrelated to this PR.

@benaryorg
Copy link
Author

I have confirmed this patch to work on both 2025.2.3 and 2025.8.3 on my end.

Some of the files I uploaded intermediately (I think with a different patch) needed a reupload since their URLs had duplicate prefixes (https://id-static.benary.org/media/public/media/public/application-icons/50352242-5439-41e8-bc38-94a7a28535d2.svg).
Given that the files did not work at all prior to that I don't think this is much of a problem.

Removing the custom_domain option will yield the usual endpoint-based URls with valid signatures all the same.

Copy link

codecov bot commented Sep 29, 2025

Codecov Report

❌ Patch coverage is 16.66667% with 5 lines in your changes missing coverage. Please review.
✅ Project coverage is 92.61%. Comparing base (87a0001) to head (217964c).
⚠️ Report is 10 commits behind head on main.

Files with missing lines Patch % Lines
authentik/root/storages.py 16.66% 5 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #17087      +/-   ##
==========================================
- Coverage   92.96%   92.61%   -0.35%     
==========================================
  Files         857      857              
  Lines       46609    46610       +1     
==========================================
- Hits        43331    43169     -162     
- Misses       3278     3441     +163     
Flag Coverage Δ
e2e 44.56% <0.00%> (-1.44%) ⬇️
integration 23.07% <0.00%> (-0.06%) ⬇️
unit 91.05% <16.66%> (+<0.01%) ⬆️
unit-migrate 91.10% <16.66%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@BeryJu
Copy link
Member

BeryJu commented Oct 9, 2025

We're still planning to rework file management but for the time being this should be a good fix

S3 signatures are fickle since there are several hashes of components which must ultimately be correct for the signature to match with no room for error.
Since both the *host* header as well as the path, the former by default, the latter necessarily.
The issue with custom domains is therefore that the *host* header mismatches unless the signature was created for that specific domain.
This is complicated further by *boto3* making it incredibly difficult to actually sign a link with the path *not* containing the bucket prefix.
Therefore setting the endpoint alone does not work with a truly custom domain (i.e. one where the data resides on the root of the domain).

Changing this to a rather hacky workaround accessing fields of the internal data structures and grabbing the signer directly allows for signing the request.
This comes with several caveats such as the parameters going largely untouched, however in preliminary testing it works fine.
There are no superfluous slashes (i.e. no `https://example.com//file.svg`), no superfluous prefixes (i.e. `https://example.com/example.com/example.com/file.svg`), and there are no signature errors in general.
Uploads still work.
Reminder that the application cache may need clearing before the changes reflect in the non-admin UI.

Relates:

- [issue 13463](https://redirect.github.com/goauthentik/authentik/issues/13463)
- [pr 14706 ](https://redirect.github.com/goauthentik/authentik/pull/14706)

Signed-off-by: benaryorg <[email protected]>
@BeryJu BeryJu force-pushed the custom-domain-fix branch from 31b43d0 to 1b1de72 Compare October 10, 2025 11:40
Signed-off-by: Jens Langhammer <[email protected]>
@BeryJu BeryJu force-pushed the custom-domain-fix branch from 1b1de72 to 217964c Compare October 10, 2025 11:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants